package com.umeox.watch.moto.settings.ui;


import static com.umeox.moto.common.utils.LanguageConfig.initialsToUpperCase;

import android.content.Intent;
import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.umeox.moto.common.utils.LanguageConfig;
import com.umeox.moto.common.utils.SystemUtils;
import com.umeox.moto.watch.themes.app.ThemeAppCompatActivity;
import com.umeox.watch.moto.settings.R;
import com.umeox.watch.moto.settings.adapter.LanguageAdapter;
import com.umeox.watch.moto.settings.bean.LanguageBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class LanguageActivity extends ThemeAppCompatActivity {


    final List<LanguageBean> list = new ArrayList<>();
    private LanguageAdapter mAdapter;

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.act_language);
        RecyclerView listView = findViewById(R.id.lv_language_list);
        findViewById(R.id.iv_done).setOnClickListener(v -> {
            final Locale locale = mAdapter.getSelectedLanguage();
            final String selectedLanguage = initialsToUpperCase(locale);
            SystemUtils.setLocalLanguage(locale);
            Intent intent = new Intent();
            intent.putExtra("language", selectedLanguage);
            setResult(-1, intent);
            finish();
        });
        listView.setHasFixedSize(true);
        listView.setLayoutManager(new LinearLayoutManager(this));
        initData();
        mAdapter = new LanguageAdapter(list);
        listView.setAdapter(mAdapter);


    }

    private void initData() {
        final Locale[] locales = LanguageConfig.LOCALE_IQIBLA_KID;
        for (Locale value : locales) {
            final LanguageBean languageBean = new LanguageBean();
            languageBean.setLocale(value);
            languageBean.setSelection(Locale.getDefault().equals(value));
            list.add(languageBean);
        }

    }

}
